package cn.qhuan.modules.controller;

import cn.qhuan.modules.dtos.ExhiDto;
import cn.qhuan.modules.dtos.ExhiTimeDto;
import cn.qhuan.modules.entity.Exhibition;
import cn.qhuan.modules.service.IExhibitionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* @Description: 展厅表
* @Author: 司翔宇
* @Date:   2020-12-18
* @Version: V1.0
*/
@Api(tags="展厅表")
@RestController
@RequestMapping("/exhibition")
@Slf4j
public class ExhibitionController extends JeecgController<Exhibition, IExhibitionService> {
    @Autowired
    private IExhibitionService exhibitionService;

    /**
     * 条件分页查询
     * @param exhiDto
     * @return
     */
    @AutoLog(value = "展厅表-条件分页查询")
    @ApiOperation(value="展厅表-条件分页查询", notes="展厅表-条件分页查询")
    @PostMapping(value = "/list")
    public Result<?> findByKeyWord(@RequestBody ExhiDto exhiDto){
        return exhibitionService.findByKeyWord(exhiDto);
    }

    /**
     *   添加
     *
     * @param qhExhi
     * @return
     */
    @AutoLog(value = "展厅表-添加")
    @ApiOperation(value="展厅表-添加", notes="展厅表-添加")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody Exhibition qhExhi) {
        exhibitionService.save(qhExhi);
        return Result.OK("添加成功！");
    }

    /**
     *  编辑
     *
     * @param qhExhi
     * @return
     */
    @AutoLog(value = "展厅表-编辑")
    @ApiOperation(value="展厅表-编辑", notes="展厅表-编辑")
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody Exhibition qhExhi) {
        exhibitionService.updateById(qhExhi);
        return Result.OK("编辑成功!");
    }

    /**
     *   通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "展厅表-通过id删除")
    @ApiOperation(value="展厅表-通过id删除", notes="展厅表-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name="id",required=true) String id) {
        exhibitionService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     *  批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "展厅表-批量删除")
    @ApiOperation(value="展厅表-批量删除", notes="展厅表-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
        this.exhibitionService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "展厅表-通过id查询")
    @ApiOperation(value="展厅表-通过id查询", notes="展厅表-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
        Exhibition qhExhi = exhibitionService.getById(id);
        if(qhExhi==null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(qhExhi);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param qhExhi
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, Exhibition qhExhi) {
        return super.exportXls(request, qhExhi, Exhibition.class, "展厅表");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, Exhibition.class);
    }

    /**
     * 通过类别查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "展厅表-通过类别查询")
    @ApiOperation(value="展厅表-通过类别查询", notes="展厅表-通过类别查询")
    @GetMapping(value = "/queryByClassId")
    public Result<?> queryByClassId(@RequestParam(name="id",required=true) String id) {
        List<String> worksIdsByClassId = exhibitionService.findExhiIdsByClassId(id);
        List<Exhibition> list =new ArrayList<>();
        Exhibition qhExhi =null;
        for (String s : worksIdsByClassId) {
            qhExhi = exhibitionService.getById(s);
            list.add(qhExhi);
        }

        return Result.OK(list);

    }


    /**
     * 通过时间查询正在进行的展厅
     * @return
     */
    @AutoLog(value = "展厅表-通过时间查询正在进行的展厅")
    @ApiOperation(value="展厅表-通过时间查询正在进行的展厅", notes="展厅表-通过时间查询正在进行的展厅")
    @PostMapping(value = "/queryunderwayByTime")
    public Result<?> queryexhiByTime(@RequestBody ExhiTimeDto exhiTimeDto) {

       return exhibitionService.findExhiByTime(exhiTimeDto);
    }

    /**
     * 通过时间查询已经结束的展厅
     * @param exhiTimeDto
     * @return
     */
    @AutoLog(value = "展厅表-通过时间查询已经结束的展厅")
    @ApiOperation(value="展厅表-通过时间查询已经结束的展厅", notes="展厅表-通过时间查询已经结束的展厅")
    @PostMapping(value = "/queryendByTime")
    public Result<?> queryEndexhiByTime(@RequestBody ExhiTimeDto exhiTimeDto) {

        return exhibitionService.findEndExhiByTime(exhiTimeDto);
    }

    /**
     * 通过时间查询未开始的展厅
     * @param exhiTimeDto
     * @return
     */
    @AutoLog(value = "展厅表-通过时间查询未开始的展厅")
    @ApiOperation(value="展厅表-通过时间查询未开始的展厅", notes="展厅表-通过时间查询未开始的展厅")
    @PostMapping(value = "/querynostartedByTime")
    public Result<?> queryNotStartedexhiByTime(@RequestBody ExhiTimeDto exhiTimeDto) {

        return exhibitionService.findNoStartedByTime(exhiTimeDto);
    }

    /**
     * 默认加载10条最新数据
     * @param exhiTimeDto
     * @return
     */
    @AutoLog(value = "展厅表-默认加载最新的展厅")
    @ApiOperation(value="展厅表-默认加载最新的展厅", notes="展厅表-默认加载最新的展厅")
    @PostMapping(value = "/LoadNewList")
    public Result<?> loadNewExhiList(@RequestBody ExhiTimeDto exhiTimeDto){
        return exhibitionService.loadNewExhiList(exhiTimeDto);
    }

    /**
     * 通过艺术家id展示在线展厅
     * @param artistId
     * @return
     */
    @AutoLog(value = "展厅表-通过艺术家id展示在线展厅")
    @ApiOperation(value="展厅表-通过艺术家id展示在线展厅", notes="展厅表-通过艺术家id展示在线展厅")
    @PostMapping(value = "/queryExhiByArtistId")
    public Result<?> queryExhiByArtistId(@RequestParam(name="id",required=true) String artistId){
        return exhibitionService.queryExhiByArtistId(artistId);
    }
    /**
     * 根据展厅id查询关联的作品
     * @param dto
     * @return
     */
    @AutoLog(value = "展厅表-根据展厅id查询关联的作品")
    @ApiOperation(value="展厅表-根据展厅id查询关联的作品", notes="展厅表-根据展厅id查询关联的作品")
    @PostMapping(value = "/findWorksListByExhiId")
    public Result<?> findWorksListByExhiId(@RequestBody ExhiDto dto){
        return exhibitionService.findWorksListByExhiId(dto);
    }
}
